package edu.rit.varapp.datalayer;

import java.util.ArrayList;

/**
 * Represents the customer table in the database.
 */
public class Customer {

    private int EntityId;
    private String ContactName;
    private String CompanyName;
    private String Addr1;
    private String Addr2;
    private String City;
    private String State;
    private int Zipcode;
    private String Email;

    /**
     * Creates a Customer object using a collection of strings. The list must contain the strings in the correct order
     * as the full constructor.
     */
    public Customer( ArrayList<String> data ) {
        this.EntityId = Integer.valueOf( data.get( 0 ) );
        this.ContactName = data.get( 1 );
        this.CompanyName = data.get( 2 );
        this.Addr1 = data.get( 3 );
        this.Addr2 = data.get( 4 );
        this.City = data.get( 5 );
        this.State = data.get( 6 );
        this.Zipcode = Integer.valueOf( data.get( 7 ) );
        this.Email = data.get( 8 );
    }

    public Customer( int EntityId, String ContactName ) {
        this.EntityId = EntityId;
        this.ContactName = ContactName;
    }

    public Customer( int EntityId, String ContactName, String CompanyName ) {
        this.EntityId = EntityId;
        this.ContactName = ContactName;
        this.CompanyName = CompanyName;
    }

    /**
     * Full constructor.
     */
    public Customer( int EntityId, String ContactName, String CompanyName, String Addr1, String Addr2, String City,
                     String State, int Zip, String Email ) {
        this.EntityId = EntityId;
        this.ContactName = ContactName;
        this.CompanyName = CompanyName;
        this.Addr1 = Addr1;
        this.Addr2 = Addr2;
        this.City = City;
        this.State = State;
        this.Zipcode = Zip;
        this.Email = Email;
    }

    public String getAddr1() {
        return Addr1;
    }

    public String getAddr2() {
        return Addr2;
    }

    public String getCity() {
        return City;
    }

    public String getCompanyName() {
        return CompanyName;
    }

    public String getContactName() {
        return ContactName;
    }

    public String getEmail() {
        return Email;
    }

    public int getEntityId() {
        return EntityId;
    }

    public String getState() {
        return State;
    }

    public int getZipcode() {
        return Zipcode;
    }

    @Override
    public String toString() {
        return "Customer{\n" + "EntityId=" + EntityId
               + "\nContactName=" + ContactName
               + "\nCompanyName=" + CompanyName
               + "\nAddr1=" + Addr1
               + "\nAddr2=" + Addr2
               + "\nCity=" + City
               + "\nState=" + State
               + "\nZipcode=" + Zipcode
               + "\nEmail=" + Email + '}';
    }

    public static String columnsToSQL() {
        return "EntityId, ContactName, CompanyName, Addr1, Addr2, City, State, Zip, Email";
    }

    /**
     * Returns the values of this object with or without single quotes.
     * @param sqlCall Flag that says if we want to wrap strings with single quotes (for SQL queries). Set flag to true
     *                if we want single quotes, else false.
     * @return
     */
    public String valuesToSQL( boolean sqlCall ) {
        if( sqlCall ) {
            return (EntityId + ", '" + ContactName + "', '" + CompanyName + "', '"
                    + Addr1 + "', '" + Addr2 + "', '" + City + "', '" + State + "', '"
                    + Zipcode + "', '" + Email + "'").trim();
        } else {
            return (EntityId + ", " + ContactName + ", " + CompanyName + ", "
                    + Addr1 + ", " + Addr2 + ", " + City + ", " + State + ", "
                    + Zipcode + ", " + Email).trim();
        }
    }
}
